<%--
  Created by IntelliJ IDEA.
  User: 刘松
  Date: 2020/5/4
  Time: 18:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
	<head>
		<title>制度审核</title>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css?2019101815.40">
		<link rel="stylesheet" href="/lib/layui/layui/css/treeTable.css?2019101815.17">
		<link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
		<link rel="stylesheet" href="/lib/layui/layui/css/modules/layer/default/layer.css">
		<link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
		<%--js--%>
		<script type="text/javascript" src="/js/jquery/jquery-1.9.1.min.js"></script>
		<script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
		<script type="text/javascript" src="/js/base/base.js"></script>
		<script type="text/javascript" src="/lib/layui/layui/global.js"></script>
		<style>
			.layui-form-item {
				margin-bottom: 20px;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div class="header">
				<div class="headImg" style="padding-top: 10px">
					<span style="font-size:22px;margin-left:10px;color:#494d59;margin-top: 2px"><img style="margin-left:1.5%"
					                                                                                 src="../img/commonTheme/theme6/icon_summary.png"
					                                                                                 alt=""><span style="margin-left: 10px">制度审核</span></span>
				</div>
			</div>
			
			<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
				<ul class="layui-tab-title">
					<li class="layui-this">未审核</li>
					<li>已审核</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show">
						<div style="padding: 0px 8px">
							<table id="institutionUnChecked" lay-filter="institutionUnChecked"></table>
						</div>
					</div>
					<div class="layui-tab-item">
						<%--						<iframe class="iframes" src="/ProjectInfo/projectInforSupply" frameborder="0" height="100%" width="100%"></iframe>--%>
						<div style="padding: 0px 8px">
							<table id="institutionChecked" lay-filter="institutionChecked"></table>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<%--自定义事件--%>
		<script type="text/html" id="doSth">
			{{#  if(d.approveStatus == '0'){ }}
			<a class="layui-btn layui-btn-xs layui-btn-light" style="background-color:#2B7FE0" lay-event="agree">批准</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="disagree">不批准</a>
			{{#  } }}
			<a class="layui-btn layui-btn-xs" lay-event="history">历史版本</a>
		</script>
		
		<script>
            var instNumber
            var layedit
            layui.use(['table', 'element', 'layedit'], function () {
                var table = layui.table,
                    layer = layui.layer,
                    element = layui.element;
                layedit = layui.layedit;
                var unCheckedTableIns = null;

                var checkedTableIns = null;
                
                initTableIns(0);

                element.on('tab(docDemoTabBrief)', function (data) {
                    initTableIns(data.index);
                });

                function initTableIns(tabIndex) {
                    if (tabIndex == 0) {
                        unCheckedTableIns = table.render({
                            elem: '#institutionUnChecked',
                            url: '/InstitutionContent/getByApprovalUser',
                            where: {
                                instType: 1,
                                approvalUser: '1',
                                approveStatus: '0'
                            },
                            parseData: function (res) { //res 即为原始返回的数据
                                return {
                                    "code": 0, //解析接口状态
                                    "data": res.obj, //解析数据列表
                                    "count": res.totleNum,
                                };
                            },
                            page: true,
                            limit: 10,
                            cellMinWidth: 150,
                            limits: [5, 10, 15, 20, 25],
                            cols: [[
                                {
                                    field: 'instName', title: '名称', align: 'center', templet: function (d) {
                                        return '<a href="javascript:;" style="text-decoration:underline;color:blue">' + d.instName + '</a>'
                                    }, event: 'title'
                                }
                                , {field: 'instNumber', title: '编号', align: 'center'}
                                , {
                                    field: 'approveStatus', title: '审核状态', align: 'center', templet: function (d) {
                                        if (d.approveStatus == 0) {
                                            return "待审批"
                                        } else if (d.approveStatus == 1) {
                                            return "已批准"
                                        } else if (d.approveStatus == 2) {
                                            return "未批准"
                                        } else if (d.approveStatus == 3) {
                                            return "未提交"
                                        }
                                    }
                                }
                                , {
                                    field: 'instStatus', title: '使用状态', align: 'center', templet: function (d) {
                                        if (d.instStatus == 0) {
                                            return "停用"
                                        } else {
                                            return "生效"
                                        }
                                    }
                                },
                                {field: 'version', title: '当前版本', align: 'center'},
                                {field: '', title: '操作', align: 'right', toolbar: '#doSth', width: 220}
                            ]]
                        });
                    } else if (tabIndex == 1) {
                        checkedTableIns = table.render({
                            elem: '#institutionChecked',
                            url: '/InstitutionContent/getByApprovalUser',
                            where: {
                                instType: 1,
                                approvalUser: '1',
                                approveStatus: '1'
                            },
                            parseData: function (res) { //res 即为原始返回的数据
                                return {
                                    "code": 0, //解析接口状态
                                    "data": res.obj, //解析数据列表
                                    "count": res.totleNum,
                                };
                            },
                            page: true,
                            limit: 10,
                            cellMinWidth: 150,
                            limits: [5, 10, 15, 20, 25],
                            cols: [[
                                {
                                    field: 'instName', title: '名称', align: 'center', templet: function (d) {
                                        return '<a href="javascript:;" style="text-decoration:underline;color:blue">' + d.instName + '</a>'
                                    }, event: 'title'
                                }
                                , {field: 'instNumber', title: '编号', align: 'center'}
                                , {
                                    field: 'approveStatus', title: '审核状态', align: 'center', templet: function (d) {
                                        if (d.approveStatus == 0) {
                                            return "待审批"
                                        } else if (d.approveStatus == 1) {
                                            return "已批准"
                                        } else if (d.approveStatus == 2) {
                                            return "未批准"
                                        } else if (d.approveStatus == 3) {
                                            return "未提交"
                                        }
                                    }
                                }
                                , {
                                    field: 'instStatus', title: '使用状态', align: 'center', templet: function (d) {
                                        if (d.instStatus == 0) {
                                            return "停用"
                                        } else {
                                            return "生效"
                                        }
                                    }
                                },
                                {field: 'version', title: '当前版本', align: 'center'}
                            ]]
                        });
                    }
                }

                table.on('tool(institutionUnChecked)', function (obj) {
                    var event = obj.event;
                    var data = obj.data;
                    instNumber = data.instNumber
                    // 同意执行的做作
                    if (event == "agree") {
                        layer.open({
                            title: '消息',
                            type: 1,
                            content: '<h3 style="margin-left: 15px;padding:10px; margin-top:15px;">您确定批准当前制度吗？</h3>',
                            area: ['300px', '200px'],
                            btn: ['确定', '取消'],
                            yes: function (index) {
                                $.ajax({
                                    type: 'get',
                                    url: '/InstitutionContent/editContent',
                                    data: {
                                        instId: data.instId,
                                        approveStatus: 1,
                                        instNumber: data.instNumber,
                                        instStatus: '1',
                                        isEdit: "编辑"
                                    },
                                    success: function (res) {
                                        if (res.flag) {
                                            unCheckedTableIns.reload();
                                        }
                                    }
                                })
                                layer.close(index);
                            }
                        })
                    }
                    // 不同意执行的操作
                    if (event == "disagree") {
                        layer.open({
                            title: '消息确认',
                            type: 1,
                            content: '<h3 style="margin-left: 15px;padding:10px; margin-top:15px;">您确定不批准当前制度吗？</h3>',
                            area: ['300px', '200px'],
                            btn: ['确定', '取消'],
                            yes: function (index) {
                                $.ajax({
                                    type: 'get',
                                    url: '/InstitutionContent/editContent',
                                    data: {
                                        instId: data.instId,
                                        approveStatus: 2,
                                        instNumber: data.instNumber,
                                        instStatus: '0',
                                        isEdit: "编辑"
                                    },
                                    success: function (res) {
                                        if (res.flag) {
                                            unCheckedTableIns.reload();
                                        }
                                    }
                                })
                                layer.close(index);
                            }

                        })
                    }
                    // 查看历史版本执行的操作
                    if (event == "history") {
                        //历史版本
                        window.open("/institution/historicalVersion?instId=" + data.instId)
                    }
                    // 查看文档的操作
                    if (event == "title") {
                        if (data.instType == 1) {
                            layer.open({
                                type: 2,
                                isOutAnim: true,
                                maxmin: true,
                                // title:data.instName,
                                area: ['100%', '100%'],
                                title: '制度详情',
                                btnAlign: 'c',
                                btn: ['返回'],
                                content: '/institution/selectInstitution?instId=' + data.instId,
                                yes: function (index) {
                                    layer.close(index);
                                },
                                btn2: function (index) {
                                    layer.close(index);
                                }
                            });


                        }

                    }
                })
	            
	            table.on('tool(institutionChecked)', function (obj) {
                    var event = obj.event;
                    var data = obj.data;
                    instNumber = data.instNumber
                    // 查看文档的操作
                    if (event == "title") {
                        if (data.instType == 1) {
                            layer.open({
                                type: 2,
                                isOutAnim: true,
                                maxmin: true,
                                // title:data.instName,
                                area: ['100%', '100%'],
                                title: '制度详情',
                                btnAlign: 'c',
                                btn: ['返回'],
                                content: '/institution/selectInstitution?instId=' + data.instId,
                                yes: function (index) {
                                    layer.close(index);
                                },
                                btn2: function (index) {
                                    layer.close(index);
                                }
                            });


                        }

                    }
                })
            })
		</script>
	</body>
</html>
